package com.javacoo.swing.jxbrowser.content;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import com.javacoo.swing.jxbrowser.BaseBrowser;
import com.teamdev.jxbrowser.chromium.BeforeSendHeadersParams;
import com.teamdev.jxbrowser.chromium.BeforeURLRequestParams;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserContext;
import com.teamdev.jxbrowser.chromium.HttpHeaders;
import com.teamdev.jxbrowser.chromium.NetworkService;
import com.teamdev.jxbrowser.chromium.ResourceHandler;
import com.teamdev.jxbrowser.chromium.ResourceParams;
import com.teamdev.jxbrowser.chromium.ResourceType;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import com.teamdev.jxbrowser.chromium.swing.DefaultNetworkDelegate;

/**
 * HTTP服务器白名单
 * <li></li>
 * HTTP服务器授权白名单
 *
 * 从6.8开始，您可以使用HTTP服务器授权白名单配置JxBrowser，该白名单表示以逗号/分号分隔的URL列表的字符串。例如：
 *
 * Browser browser = new Browser();
 * BrowserContext browserContext = browser.getContext();
 * NetworkService networkService = browserContext.getNetworkService();
 * networkService.setServerWhiteList("*google.com,*example.com,*baz");
 *
 * HTTP网络委托白名单
 *
 * 要使用HTTP网络委托白名单配置JxBrowser， 您可以使用下面描述的方法：
 *
 * Browser browser = new Browser();
 * BrowserContext browserContext = browser.getContext();
 * NetworkService networkService = browserContext.getNetworkService();
 * networkService.setDelegateWhiteList("*google.com,*example.com,*baz");
 *
 * 此功能自6.8起可用
 * @author: duanyong@jccfc.com
 * @since: 2020/9/27 9:04
 */
public class HTTPServerWhitelist extends BaseBrowser {
    public static void main(String[] args) {
        BrowserContext browserContext = BrowserContext.defaultContext();
        //HTTP服务器授权白名单
        browserContext.getNetworkService().setServerWhiteList("*google.com,*example.com,*baz");
        //HTTP网络委托白名单
        browserContext.getNetworkService().setDelegateWhiteList("*google.com,*example.com,*baz");
        Browser browser = new Browser(browserContext);
        BrowserView browserView = new BrowserView(browser);
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(browserView, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);



        browser.loadURL(BASE_URL);
    }
}
